package com.iot.auth.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.iot.auth.service.IOauthService;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Controller
@RequestMapping("/oauth")
public class OauthController {

	private final IOauthService oauthService;

	@PostMapping("/logout")
	public void logout(HttpServletRequest request, HttpServletResponse response) {
	}

	@PostMapping("/authorize")
	public void authorize(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "client_id", required = false) String client_id,
			@RequestParam(name = "client_secret", required = false) String client_secret,
			@RequestParam(name = "redirect_uri", required = false) String redirect_uri,
			@RequestParam(name = "grant_type", required = false) String grant_type,
			@RequestParam(name = "username", required = false) String username,
			@RequestParam(name = "password", required = false) String password,
			@RequestParam(name = "state", required = false) String state) {
		oauthService.createToken(request, response, username, password);
	}

	@PostMapping("/check_token")
	public void check_token(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "token", required = true) String token) {
		oauthService.checkToken(request, response, token);
	}
	

	

	@PostMapping("/refresh_token")
	public void refresh_token(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "token", required = true) String token) {
		oauthService.checkToken(request, response, token);
	}

	@PostMapping("/cancel_token")
	public void cancel_token(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "token", required = true) String token) {
		oauthService.checkToken(request, response, token);
	}

	@PostMapping("/confirm_access")
	public void confirm_access(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "token", required = true) String token) {
	}

	@PostMapping("/token_key")
	public void token_key(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "token", required = true) String token) {
	}

	@PostMapping("/error")
	public void error(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(name = "token", required = true) String token) {
	}

//	/oauth/authorize：授权端点。
//	/oauth/token：令牌端点。
//	/oauth/confirm_access：用户确认授权提交端点。
//	/oauth/error：授权服务错误信息端点。
//	/oauth/check_token：用于资源服务访问的令牌解析端点。
//	/oauth/token_key：提供公有密匙的端点，如果你使用JWT令牌的话。

}
